# -*- coding: utf-8 -*-
# @Time        :2025/2/27 20:48
# @Author      :文刀水寿
# @File        : 5_爬虫_urllib_get请求的quote方法.py
"""
 @Description :
"""
import time
# 需求：获取https://www.baidu.com/s?wd=周杰伦的网页的源码

import urllib.request
import urllib.parse

url = 'https://www.baidu.com/s?wd='
# 请求对象的定制为了解决反爬的第一种手段
headers = {
    'accept': 'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8',
    'user-agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0",
    'cookie': 'BIDUPSID=37E7FD100566DBC3BC65F3F7BDBDC4A9; PSTM=1738571532; BAIDUID=9E3BE1F1582275297787F9B02D5D4F8E:FG=1; BAIDUID_BFESS=9E3BE1F1582275297787F9B02D5D4F8E:FG=1; ZFY=UbRkXsnPsyuHe:ASSOh2DZ0QxGpABix:Ah504KQQefL7I:C; BA_HECTOR=0k2g0g218081a4040h818h8k117b2c1jrvleh1v; PSINO=2; H_PS_PSSID=61027_62080_62130_62128_62168_62176_62185_62186_62181_62194_62201_62133_62325; delPer=0; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; __bid_n=195477afa15859268dab62; ab_sr=1.0.1_N2I0NGMxOWQ0MzNiMGNiMDY1ZTQyMjdkNTA4OTFkNDcwMzEzZjAyM2ZlMjA0N2UzYjQwYjQzZDAyZjAwM2VjN2NmNTJhMjkwODYxYTMwNTUzMmRkOGRmZGE3NjAzZWJkNDBhMjY1MGI2ODY3MTc3MDAzZmExZjY2Zjc5ZDk2YzZhMDUzN2RhNzUyN2U5ODU2ZmNlMjI3ZGM0YzQ5YzIzZQ=='
}

# 将周杰伦三个字变为unicode编码的格式
# 我们需要依赖urllib parse
name = urllib.parse.quote('周杰伦')

url = url + name

# 请求对象的定制
request = urllib.request.Request(url=url, headers=headers)

# 模拟浏览器向服务器发送请求
response = urllib.request.urlopen(request)

# 获取响应的内容
content = response.read().decode('utf8')

# 打印
print(content)
time.sleep(1)
